import 'package:camera/camera.dart';
import 'package:clean_app/asset/color.dart';
import 'package:clean_app/provider/font_size_provider.dart';
import 'package:clean_app/provider/login_provider.dart';
import 'package:clean_app/provider/tabs_provider.dart';
import 'package:clean_app/provider/task_provider.dart';
import 'package:clean_app/router/router.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:provider/provider.dart';

late List<CameraDescription> cameras;

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  cameras = await availableCameras();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (context) => UserProvider()),
        ChangeNotifierProvider(create: (context) => FontSizeProvider()),
        ChangeNotifierProvider(create: (context) => TabsProvider()),
        ChangeNotifierProvider(create: (context) => TaskProvider()),
        ChangeNotifierProvider(create: (context) => PresetTagProvider()),
      ],
      child: Builder(builder: (context) {
        return AnnotatedRegion<SystemUiOverlayStyle>(
          value: SystemUiOverlayStyle(
            statusBarColor: Colors.transparent,
            systemNavigationBarColor: os_white,
          ),
          child: MaterialApp(
            title: '清洁App',
            localizationsDelegates: const [
              GlobalMaterialLocalizations.delegate,
              GlobalWidgetsLocalizations.delegate,
              GlobalCupertinoLocalizations.delegate,
            ],
            supportedLocales: const [
              Locale('zh', 'CN'), //设置语言为中文
            ],
            debugShowCheckedModeBanner: false,
            theme: ThemeData(
              colorScheme: ColorScheme.fromSeed(seedColor: Colors.blueAccent),
              useMaterial3: true,
              appBarTheme: AppBarTheme(
                surfaceTintColor: Colors.transparent,
                scrolledUnderElevation: 0,
              ),
            ),
            initialRoute: "/",
            onGenerateRoute: (settings) {
              final String routersname = settings.name!;
              final Function cotrollerFn = routers[routersname]!;
              if (settings.arguments == null) {
                return CupertinoPageRoute(
                  builder: (context) => cotrollerFn(),
                );
              } else {
                return CupertinoPageRoute(
                  builder: (context) => cotrollerFn(settings.arguments),
                );
              }
            },
          ),
        );
      }),
    );
  }
}
